<?php
 
define('ADMIN_URL', 'http://121.43.179.32:8080/dumi_pay');

define('GMIP1', '127.0.0.1');
define('GMPort1', 18888); 

define('DS', DIRECTORY_SEPARATOR);
define('BASE_DIR', dirname(__FILE__));
define('LOG_PATH', BASE_DIR . DS . 'log' . DS);

date_default_timezone_set('Asia/Shanghai');

$bean_qc_lv = 200000;
$card_qc_lv = 200000;

$db_config = array(
    'db_host' => '127.0.0.1',
    'db_port' => '3306',
    'db_user' => 'root',
    'db_pwd' => '55668888Ee*-',
    'db_name' => 'shao',
);

$gm_config = array(
    'db_host' => '127.0.0.1',
    'db_port' => '3306',
    'db_user' => 'root',
    'db_pwd' => '55668888Ee*-',
    'db_name' => 'z_game_log',
);



/* -----------------------------------------------public function ------------------------------------------------------------- */

/**
 * 生成签名
 * @param array params 签名数据
 * @param string app_key 签名秘钥
 * @return string 签名串
 */
function gen_sign($params, $app_key) {
    ksort($params);
    $str = '';
    foreach ($params as $k => $v) {
        $str .= $k . '=' . $v . '&';
    }
    $str .= 'key=' . $app_key;
    $signature = md5($str);
    return $signature;
}

/**
 * 验证签名
 * @return boolean * 生成签名
 * @param array params 签名数据
 * @param string app_key 签名秘钥
 * @return boolean true|flase
 */
function check_sign($params, $app_key) {
    if (empty($params['signature'])) {
        return false;
    }
    ksort($params);
    $str = '';
    $signature = $params['signature'];
    foreach ($params as $k => $v) {
        if ($k != 'signature' and $v !== '') {
            $str .= $k . '=' . $v . '&';
        }
    }
    $str .= 'key=' . $app_key;
    if ($signature == md5($str)) {
        return true;
    }
    return false;
}

function write_log_file($data) {
    if (is_array($data)) {
        file_put_contents(LOG_PATH . date('Y-m-d') . ".log", date('Y-m-d H:i:s') . @json_encode($data) . "\n", FILE_APPEND);
    } else {
        file_put_contents(LOG_PATH . date('Y-m-d') . ".log", date('Y-m-d H:i:s') . $data . "\n", FILE_APPEND);
    }
}
 